@extends('layouts/admin')
    @section('content')
        <!--面包屑导航 开始-->
        <div class="crumb_warp">
            <i class="fa fa-home"></i> <a href="{{url('admin/info')}}">首页</a> &raquo; 自定义导航管理
        </div>
        <!--面包屑导航 结束-->
        <!--结果集标题与导航组件 开始-->
        <div class="result_wrap">
            <div class="result_title">
                <h3>自定义导航管理</h3>
            </div>
            <div class="result_content">
                <div class="short_wrap">
                    <a href="{{url('admin/navs/create')}}"><i class="fa fa-plus"></i>添加导航</a>
                    <a href="{{url('admin/navs')}}"><i class="fa fa-fw fa-list-ul"></i>全部导航</a>
                </div>
            </div>
        </div>
        <!--结果集标题与导航组件 结束-->
        @if(session('success'))
        <div class="result_title">
                <div class="mark" style="background-color: #66CC99;">
                    <p style="color: green;">{{session('success')}}</p>
                </div>
        </div>
        @endif
        <!--搜索结果页面 列表 开始-->
        <form action="#" method="post">
            <div class="result_wrap">
                <div class="result_content">
                    <table class="list_tab">
                        <tr>
                            <th class="tc">排序</th>
                            <th class="tc">ID</th>
                            <th>导航名称</th>
                            <th>导航别名</th>
                            <th>导航地址</th>
                            <th>操作</th>
                        </tr>
                        @foreach($data as $result)
                            <tr>
                                <td class="tc">
                                    <input type="text" name="navs_order" value="{{$result->nav_order}}" onchange="changeOrder(this,{{$result->nav_id}})">
                                </td>
                                <td class="tc">{{$result->nav_id}}</td>
                                <td>{{$result->nav_name}}</td>
                                <td>
                                    <a href="#">{{$result->nav_alias}}</a>
                                </td>
                                <td>{{$result->nav_url}}</td>
                                <td>
                                    <a href="{{url('admin/navs/'.$result->nav_id.'/edit')}}">修改</a>
                                    <a href="javascript:" onclick="return delNav({{$result->nav_id}})">删除</a>
                                </td>
                            </tr>
                        @endforeach 
                    </table>
                </div>
            </div>
        </form>
        <!--搜索结果页面 列表 结束-->
        <script type="text/javascript">
            // 异步更新排序
            function changeOrder(obj,nav_id){
                var nav_order = $(obj).val();
                $.post("{{url('admin/navs/changeorder')}}", 
                    {'_token': '{{csrf_token()}}', 'nav_id': nav_id, 'nav_order': nav_order }, 
                    function ($data) {
                        if ($data['status'] === '1' ) {
                            layer.msg($data['msg'], {icon: 6});
                            setTimeout(function () {
                                location.href = location.href;
                            }, 1000);
                        } else {
                            layer.msg($data['msg'], {icon: 5});
                            setTimeout(function () {
                                location.href = location.href;
                            }, 1000);
                        }
                    });
            }
            function delNav(nav_id){
                layer.confirm('确定删除吗？', {
                  btn: ['确定','取消'] //按钮
                }, function(){
                  $.post("{{url('admin/navs/')}}/"+nav_id,{'_token': "{{csrf_token()}}", '_method': 'delete' }, function (data) {
                        if(data.status == 1){
                            layer.msg(data.msg, {icon: 6});
                            setTimeout(function () {
                                location.href = location.href;
                            }, 1000);
                        }else{
                            layer.msg(data.msg, {icon: 5});
                            setTimeout(function () {
                                location.href = location.href;
                            }, 1000);
                        }
                  });
                }, function(){
                    
                });
            }
        </script>
    @stop
